import java.util.Hashtable;
import java.util.*;
import java.awt.event.*;
import java.awt.*;

public class ClientIHMView extends Frame implements ClientIHM_itf {

	private Hashtable<Integer, SharedObject> ids;
	private Hashtable<Integer, String> names;
	private TextArea text;

	public ClientIHMView(Hashtable<Integer, SharedObject> ids) {
		this.ids = ids;
		this.names = new Hashtable<Integer, String>();

		setLayout(new FlowLayout());

		this.setLocation(0, 300);
		text = new TextArea(10,30);
		text.setEditable(false);
		text.setForeground(Color.white);
		add(text);

		setSize(300, 250);
		text.setBackground(Color.black);
		setVisible(true);
	}

	public void maj() {
		text.setText(""); 
		text.append("Lock | ID | NAME\n");
		
		String tab = new String();
		for(Enumeration k = ids.keys() ; k.hasMoreElements() ; ) {
			SharedObject so = ids.get(k.nextElement());
			text.append(so.getLock() + " | ");
			text.append(Integer.toString(so.getId()) + "  | ");
			String name = names.get(so.getId());
			if(name == null) {
				name = "unnamed";
			}
			text.append(name + "\n");
		}
	}

	public void register(int id, String name) {
		names.put(id, name);
		maj();
	}

}	
